package win.zxshuo.www.repository.chapters;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import win.zxshuo.www.model.chapters.Chapter10Model;
import win.zxshuo.www.model.chapters.Chapter5Model;
import win.zxshuo.www.model.chapters.ChapterModel;

import java.util.List;


@Repository
public interface Chapter10Repository extends JpaRepository<Chapter10Model,Long> {

    @Query(value = "select * from chapter10 WHERE spiderStatus='0' limit 100;",nativeQuery = true)
    public List<Chapter10Model> getUnCrawlerUrlLimitOnehundred();

    public Chapter10Model findByBookIdAndSpiderUrlAndTitle(Long bookid, String spiderUrl, String title);

    public List<Chapter10Model> findAllByBookId(Long bookid);

    @Query(value = "select * from chapter10 where bookid=?1 and id>=?2 limit 2",nativeQuery = true)
    public List<Chapter10Model> findNextChapterBy(Long bookid, Long chapterid);

    @Query(value = "select * from chapter10 where bookid=?1  and id<=?2 order by id desc limit 2",nativeQuery = true)
    public List<Chapter10Model> findPreviousChapterBy(Long bookid,Long chapterid);

    @Query(value = "select * from chapter10 where bookid=?1 limit 1",nativeQuery = true)
    public Chapter10Model getFirstChapterByBookid(Long bookid);

    @Query(value = "select * from chapter10 where bookid=?1 order by id desc  limit 1",nativeQuery = true)
    public Chapter10Model getLastChapterByBookid(Long bookid);

    @Query(value = "select * from chapter10 where bookid=?1 order by id desc limit 3;",nativeQuery = true)
    public List<Chapter10Model> getLastThreeChapterByBookId(Long bookid);

    /**
     * 查询书籍未采集的url
     * @param bookid
     * @return
     */
    @Query(value = "select * from chapter10 where bookid=?1 and spiderStatus != 1",nativeQuery = true)
    public List<Chapter10Model> getAllUncrawlerBookByBookId(Long bookid);
}
